package sunwin.yoms.service.publicty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.dao.VideoTypeDao;
import sunwin.yoms.domain.publicty.VideoTypeDomain;

import java.util.List;

/**
 * Created by watson on 2015/7/28.
 */
@Service
public class VideoTypeService {
    @Autowired
    private VideoTypeDao videoTypeDao;

    //查询
    public List<VideoTypeDomain> getVideoTypeDomain(VideoTypeDomain videoTypeDomain) {
        List<VideoTypeDomain> videoTypeDomains = videoTypeDao.getDomainCollection(videoTypeDomain);
        return videoTypeDomains;
    }

    //id查询
    public VideoTypeDomain getVideoTypeDomainById(int videoTypeId) {
        return videoTypeDao.getDomainById(videoTypeId);
    }

    //增加
    public void addVideoTypeDomain(VideoTypeDomain videoTypeDomain) throws YomsException {
        if (videoTypeDao.addDomain(videoTypeDomain) != 1) {
            throw new YomsException("创建视频类型失败");
        }
    }

    //删除
    public void deleteVideoTypeDomain(VideoTypeDomain videoTypeDomain) throws YomsException {
        if (videoTypeDao.deleteDomain(videoTypeDomain) != 1) {
            throw new YomsException("删除视频类型失败");
        }
    }

    //更新
    public void upVideoTypeDomain(VideoTypeDomain videoTypeDomain) throws YomsException {
        if (videoTypeDao.deleteDomain(videoTypeDomain) != 1) {
            throw new YomsException("更新视频类型失败");
        }
    }

    //总条数
    public int getCountDomain() {
        return videoTypeDao.getDomainCount();
    }
}
